package com.xiaocikuai.smallchunks.config;

import com.xiaocikuai.smallchunks.utils.SessionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.servlet.http.HttpSessionListener;

@Configuration
@EnableScheduling
public class ApplicationConfig {

    private final SessionListener sessionListener;

    @Autowired
    public ApplicationConfig(SessionListener sessionListener) {
        this.sessionListener = sessionListener;
    }

    @Scheduled(fixedRate = 60000) // 每一分钟执行一次
    public void scheduleCheckInactiveUsers() {
        sessionListener.checkAndRemoveInactiveUsers();
    }
}
